package com.ai.zhly.service;

import java.util.HashMap;
import java.util.Map;

import com.ai.dmc.index.base.impl.base.BaseServiceImpl;
import com.ai.dmc.index.common.cache.HotMapCache;
import com.ai.dmc.index.common.exception.BusinessException;
import com.ai.dmc.utils.json.JsonUtil;
import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;
import net.sf.json.JSONObject;
/**
 * 
* @Title: HotMapServiceImpl.java
* @Description:热力图service
* @author xueyf3  
* @date 2016年5月23日 下午4:22:54
* Copyright：Copyright (c) 2016
* Company：北京亚信智慧数据科技有限公司
* @version V1.0
 */
public class HotMapServiceImpl extends BaseServiceImpl implements IHotMapService{
	
    public static Logger log = LoggerFactory.getServiceLog(HotMapServiceImpl.class);

    private IHotMapUtilService hotMapUtil;
    
	public void setHotMapUtil(IHotMapUtilService hotMapUtil) {
		this.hotMapUtil = hotMapUtil;
	}

	/**
	 * 
	 * @Description : 查询热力图-实时
	 * @param regionId
	 * @return
	 * @return JSONArray
	 * 
	 * @author : wucm
	 * @date : 2015年7月7日 下午4:17:41
	 * 
	 */
	@Override
	public void queryHotMapNow(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String regionId = inputObject.getParams().get("regionId");
		JSONObject j = new JSONObject();

		if (null != HotMapCache.hotMapCache.get("now")) {
			j = (JSONObject) ((Map) HotMapCache.hotMapCache.get("now"))
					.get(regionId);
		} else {
			j = hotMapUtil.queryHotMap0(regionId);
		}
		
		resultMap.put("result", null == j ? "" :j);
        outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 查询热力图-回放模式
	 * @param regionId
	 * @return
	 * @return JSONArray
	 * 
	 * @author : wucm
	 * @date : 2015年7月7日 下午4:17:41
	 * 
	 */
	@Override
	public void queryHotMapHistory(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String regionId = inputObject.getParams().get("regionId");
		JSONObject j = new JSONObject();

		if (null != HotMapCache.hotMapCache.get("h24")) {
			j = (JSONObject) ((Map) HotMapCache.hotMapCache.get("h24"))
					.get(regionId);
		} else {
			j = hotMapUtil.queryHotMap24(regionId);
		}
		resultMap.put("result", null == j ? "" :j);
        outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 查询热力图-对比模式
	 * @param regionId
	 * @return
	 * @return JSONArray
	 * 
	 * @author : wucm
	 * @date : 2015年7月7日 下午4:17:41
	 * 
	 */
	@Override
	public void queryHotMapCheck(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String regionId = inputObject.getParams().get("regionId");
		
		JSONObject j = new JSONObject();

		if (null != HotMapCache.hotMapCache.get("h48")) {
			j = (JSONObject) ((Map) HotMapCache.hotMapCache.get("h48"))
					.get(regionId);
		} else {
			j = hotMapUtil.queryHotMap24And48(regionId);
		}
		
		resultMap.put("result", null == j ? "" :j);
        outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

}
